var fractionToDecimal = function(numerator, denominator) {
    // 求整数
    let int = Math.floor(numerator / denominator)
    if(int === 0){
        let remainder = numerator * 10 % denominator
        let decimal = Math.floor(numerator * 10 / denominator)
    }else{
        let remainder = numerator % denominator
        let decimal = Math.floor(numerator / denominator)
    }
        let remainderArr = new Array()
        let decimalArr = new Array()
        while(remainder !== 0 && remainderArr.indexOf(remainder) === -1 ){
            decimalArr.push(decimal)
            remainderArr.push(remainder) // 小数
            remainder = remainder * 10 % denominator //余数
            decimal = Math.floor(remainder * 10 / denominator)
            console.log(remainder, decimal)
        }

        if(remainder !== 0){ //小数循环
            decimalArr.push('(')
            decimal = Math.floor(remainder * 10 / denominator)
            decimalArr.push(decimal)
            let remainder2 = remainder * 10 % denominator
            while(remainder2 !== remainder){
                remainder2 = remainder2 * 10 % denominator
                decimal = Math.floor(remainder2 * 10 / denominator)
                decimalArr.push(decimal)
            }
            decimalArr.push(')')

        }
       console.log(remainderArr)
       console.log(decimalArr)
       console.log(int + '.' + decimalArr.join(''))
       return int + '.' + decimalArr.join('')
    
    

};
console.log(4/6)
fractionToDecimal(4, 6)